<template>
	<view>
		<search :placeholder="'输入合同模板名称'" @input="inputChange"></search>
		
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
			<!-- :down="downOption" :up="upOption" -->
		
			<uni-list>
		
				<view class="item" @click="goDetail(item)" v-for="(item, index) in listdata" :key="index">
		
					<view class="text-line" style="margin-top: 20rpx;">
						<text class="text-name">模板名称:</text>
						<text class="text-value">{{item.nameTpl|filterNull}}</text>
					</view>
		
					<view class="text-line">
						<text class="text-name">使用次数:</text>
						<text class="text-value">{{item.countUse|filterNull}}/次</text>
					</view>
		
					<view class="text-line">
						<text class="text-name">模板备注:</text>
						<text class="text-value">{{item.desc|filterNull}}</text>
					</view>
		
		
				</view>
			</uni-list>
		
		</mescroll-body>
		
	</view>
</template>

<script>
	import search from '@/components/search.vue';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	
	export default {
		mixins: [MescrollMixin],
		components: {
			search,
		},
		data() {
			return {
				type:'',
				page: 1,
				listdata: [],
				searchWord: "",
				from: "",
			}
		},
		methods: {
			getData() {
			
				this.$u.api.contractTemplate({
						nameTpl: this.searchWord,
						rentType: this.type,
						pageNo: this.page,
					}).then(
						res => {
							// if (res.code == 1) {
							if (this.page == 1) {

                this.listdata = [];
              }
              this.listdata = this.listdata.concat(res);
              this.mescroll.endSuccess(res.length);
              // }
						}
					)
					.catch(() => {
						this.mescroll.endErr();
					})
			},
			
			upCallback(page) {
				console.log("触发了上拉加载" + page);
			
				this.page = page.num;
				this.getData();
			},
			
			inputChange(value) {
				this.searchWord = value;
				this.getData();
			},
			
			goDetail(item){
				item.from = this.from
				uni.$emit('seltemplate', item)
				uni.navigateBack()
			}
			
		},
		onLoad(op) {
			this.type = 'null'!=op.type?op.type:''
			this.from = 'null'!=op.from?op.from:''
		},
	}
</script>

<style lang="scss" scoped>
	
</style>
